<%@ taglib uri="/tld/extremecomponents" prefix="ec" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

	<script src = "../js/jquery-1.12.1.js" type = "text/javascript"></script>
	<script src = "../js/jquery.validate.js" type = "text/javascript"></script>
	<script src = "../js/messages_zh.js" type = "text/javascript"></script>
	<script src = "../js/common.js" type = "text/javascript"></script>
	
	<link href="<%=request.getContextPath() %>/css/extremecomponents.css" rel="stylesheet" type="text/css" />
	<link href="<%=request.getContextPath() %>/css/global.css" rel="stylesheet" type="text/css" />
	<title></title>
	<!-- <style>
		#SetJob label.error {
			margin-left: 10px;
			width: auto;
			color:red;
			display: inline;
		}
	</style> -->
</head>
<body>
 <c:choose>
	    <c:when test="${CONDITIONMAP.flag == 'add'}">
   			<div id="current">当前位置：基础数据管理 &gt; 课程管理 &gt; 新建课程</div>
	    </c:when>
	    <c:when test="${CONDITIONMAP.flag == 'update'}">
   			<div id="current">当前位置：基础数据管理 &gt; 课程管理 &gt; 修改课程</div>
	    </c:when>
    </c:choose>

    <form id="addCourseForm" name="addCourseForm" method="post">
        <table width="600" height="10" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr>
                <td height="30" align="center" class="xxpage">
                	<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                         <tr>
                            <td width="14%" class="xxpage_td2">当前用户：</td>
                            <td width="86%" class="xxpage_td2">
                              	<input name="userName" id="userName" type="text"  value="${USERINFO.userCode}"   readonly="true" />
                            	<input type="hidden" name="FLAG" value="<c:out value="${CONDITIONMAP.flag}"/>" />
                            </td>
                        </tr> 
                        <tr>
                            <td class="xxpage_td2">课程名：</td>
                            <td class="xxpage_td2">
                            	<input name="COURSE_NAME" id="courseName" type="text" value="<c:out value='${COURSEINFO.course_name}'/>"  />
                            		<input name="COURSE_ID" id="COURSE_ID" type="hidden" value="<c:out value='${COURSEINFO.course_id}'/>"  />
                            </td>
                        </tr>
                        <tr>
                            <td class="xxpage_td2">课时：</td>
                            <td width="86%" class="xxpage_td2">
                              <input name="COURSE_HOUR" id="courseHour" type="text" value="<c:out value="${COURSEINFO.course_hour}"/>"  />
                            </td>
                        </tr>
                        <tr>
                            <td class="xxpage_td2">学分：</td>
                            <td class="xxpage_td2">
                            	<input name="CREDITS" id="credits" type="text" value="<c:out value='${COURSEINFO.credits}'/>"  />
                            </td>
                        </tr>
                          <tr>
                            <td class="xxpage_td2">课程性质：</td>
                            <td class="xxpage_td2">
	                             <select name = "COURSE_TYPE" id = "COURSE_TYPE">
	        						<option value = "1" >重修</option>
	        						<option value = "2" <c:if test="${CONDITIONMAP.flag == 'add'}">selected</c:if> >必修</option>
	        						<option value = "3" >选修</option>
	       						 </select>
                            </td>
                        </tr>
                    </table>
                 </td>
            </tr>
        </table>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td width="49%" height="40" align="right"><input id="btnadd" name="btnadd" type="button" class="btn_2" value="确认" /></td>
                <td width="2%" align="center">&nbsp;</td>
                <td align="left"><input id="reset" name="reset" type="reset" class="btn_2" value="重置" /></td>
            </tr>
        </table>
    </form>
<script>

//课程性质框回显
$(function() {
	var courseType = '${COURSEINFO.course_type}';
	var flag = '${CONDITIONMAP.flag}';
		if(flag == 'update'){
			$("#COURSE_TYPE").find("option[value='"+courseType+"']").attr("selected",true);
		}
	});


//增加/修改
	$("#btnadd").click(function() {
		var userName = $("#userName").val();
		var courseName = $("#courseName").val();
		var courseHour = $("#courseHour").val();
		var credits = $("#credits").val();
		var COURSE_TYPE = $("#COURSE_TYPE").val();
	    if(courseName==null || courseName=="" || courseName==''){
	        alert("课程名不可为空！");
	        return false;
	    } else if(courseHour==null || courseHour=="" || courseHour==''){
	        alert("课时不可为空！");
	        return false;
	    }else if(credits==null || credits=="" || credits==''){
	        alert("学分不可为空！");
	        return false;
	    }else if(COURSE_TYPE==null || COURSE_TYPE=="" || COURSE_TYPE==''){
	        alert("课程性质不可为空！");
	        return false;
	    }else{
	        $.ajax({
	            type : "post",
	            dataType : "text",
	            url : "course?ActionType=course_add_update",
	            data : $("#addCourseForm").serialize(),
	            success : function(massage) {
	                if (massage == 'success') {
	                	goTo("course?ActionType=course_Manage");
	                }
	                if (massage == 'fail') {
	                	alert("该课程已经存在！");
	                }
	            }
	        });
	    }
	 });
</script>
</body>
</html>